package com.xtoad.ecms.common.web.exception;

/**
 * 业务异常类
 *
 * @author xtoad
 * @date 2020/05/29
 */
public class BusinessException extends RuntimeException {
    private String code;
    private String msg;

    /**
     * 构造方法
     *
     * @param code 异常码
     * @param msg 异常消息
     */
    public BusinessException(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 构造方法
     *
     * @param resultCode 错误码对象
     */
    public BusinessException(ResultCodeEnum resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("BusinessException{");
        sb.append("code='").append(code).append('\'');
        sb.append(", msg='").append(msg).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
